import store from '../store'
import wx from 'weixin-js-sdk'
import axios from 'axios'
import qs from 'qs'

let fun = () => {
  let params = {
    app_id: store.state.app_id,
    url: encodeURIComponent(window.location.href)
  }
  axios
    .post('http://web.zhiyunzaixian.com/wechat/Authorize/wx_jssdk', qs.stringify(params))
    .then(res => {
      let { code, data } = res.data
      if (code === 200) {
        wx.config({
          debug: false,
          appId: data.appId,
          timestamp: data.timestamp,
          nonceStr: data.nonceStr,
          signature: data.signature,
          jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage']
        })
      }
    })
}
export default fun
